<template>
  <div class="container">
      <div class="header">
          <div class="store-name">永辉超市回龙观店</div>
          <img class="store-logo" src="../assets/logo.png" alt="logo">
          <p class="store-dec">欢迎光临本店，本店新开张，诚信经营！</p>
          <div class="store-others">
              <div class="deliver-place" @click="toAddressPage">请选择配送地址</div>
              <div class="search-goods">搜索商品</div>
          </div>
      </div>
      <ul class="title">
          <li :class="{'title-checked': currentTabNum == 0}" @click="activeTab(0)">全部</li>
          <li :class="{'title-checked': currentTabNum == 1}" @click="activeTab(1)">综合</li>
          <li :class="{'title-checked': currentTabNum == 2}" @click="activeTab(2)">价格</li>
      </ul>
      <div class="classify-wrapper">
          <div class="classify-nav" ref="classifyNav">
              <ul class="classify-nav-list">
                  <li class="classify-nav-item" v-for="(item, index) in 100" :key="index" :class="{'classify-nav-item-actived': currentNavNum == index}" @click="activeNavItem(index)">
                      全部{{item}}
                  </li>
              </ul>
          </div>
          <div class="classify-goods" ref="classifyGoods">
              <ul class="classify-goods-list">
                  <li class="classify-goods-item" v-for="(item, index) in goodsList" :key="index" @click="goDetails(item.id)">
                      <img class="classify-goods-img" :src="item.goodsMasterMap" :alt="item.goodsName">
                      <div class="classify-goods-con">
                          <h4 class="classify-goods-name">{{item.goodsName}}</h4>
                          <div class="classify-goods-feture">{{item.specificationName}}</div>
                          <div class="classify-goods-price">￥
                              <span class="boldNum">{{item.shopPrice|getInter}}.</span>
                              <span>{{item.shopPrice|getDot}}</span>
                          </div>
                      </div>
                  </li>
              </ul>
          </div>
      </div>
  </div>
</template>

<script>
import BScroll from 'better-scroll'
import api from '../utils/api.js'
export default {
    props: [],
    data(){
        return {
            currentNavNum: 0,
            currentTabNum: 0,
            goodsList: []
        }
    },
    methods: {
        activeNavItem(index) {
            this.currentNavNum = index;
        },
        activeTab(index) {
            this.currentTabNum = index;
        },
        toAddressPage() {
            this.$router.push({ path: 'addresslist' })
        },
        goDetails(id) {
            this.$router.push({ path: 'goodDetails', query: { id }})
        }
    },
    filters:{
        getInter(val) {
            return val.toFixed(2).split('.')[0]
        },
        getDot(val) {
            return val.toFixed(2).split('.')[1]
        }
    },
    mounted() {
       let classifyNav = document.querySelector('.classify-nav');
       this.nav = new BScroll(classifyNav, {
           click: true
       });
       let classifyGoods = this.$refs.classifyGoods;
       this.goods = new BScroll(classifyGoods, {
           click: true
       })
        api.getGoodsList()
        .then(res => {
            this.goodsList = res
        })
    }
}

</script>
<style>
.header {
    height: 2.04rem;
    background-image: linear-gradient(-203deg, #F46839 0%, #DD3333 56%);
    display: flex;
    flex-direction: column;
    align-items: center;
}
.store-name {
    height: 0.3rem;
    line-height: 0.3rem;
    width: 3.19rem;
    background: rgba(255,255,255,0.10);
    border-radius: 0.2rem;
    margin-top: 0.1rem;
    color: #fff;
    font-size: 0.1rem;
}
.store-logo {
    width: 0.6rem;
    height: 0.6rem;
    border-radius: 50%;
    margin-top: 0.16rem;
}
.store-dec {
    font-size: 0.14rem;
    color: #fff;
    margin: 0.1rem 0 0.21rem 0;
}
.store-others {
    height: 0.44rem;
    width: 100%;
    display: flex;
    background: rgba(0,0,0,0.10);
    align-items: center;
    padding: 0.14rem;
    box-sizing: border-box;
}
.deliver-place {
    width: 1.38rem;
    height: 0.3rem;
    color: #333;
    margin-right: 0.1rem;
    background: #FFFFFF;
    border-radius: 0.14rem;
    text-align: center;
    line-height: 0.3rem;
}
.search-goods {
    flex: 1;
    height: 0.3rem;
    color: #ccc;
    background: #FFFFFF;
    border-radius: 0.14rem;
    line-height: 0.3rem;
    text-align: left;
    text-indent: 0.1rem;
}
.title {
    height: 0.44rem;
    font-size: 0.18rem;
    line-height: 0.44rem;
    position: relative;
    display: flex;
    justify-content: space-around;
}
.title::after {
    position: absolute;
    content:  "";
    left: 0;
    bottom: 0;
    width: 100%;
    border-top: 1px solid #ccc;
    transform: scale(1, 0.5);
    box-shadow: 0 0.02rem 0.04rem 0 rgba(0,0,0,0.16),0 0.02rem 0.1rem 0 rgba(0,0,0,0.12);
}
.title li{
    font-size: 0.14rem;
    color: #333;
    position: relative;
    -webkit-tap-highlight-color: rgba(0,0,0,0)
}
.title-checked::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    border-bottom: 2px solid #dd3333; 
    width: 100%;
}
.classify-wrapper {
    position: absolute;
    top: 2.48rem;
    bottom: 0.49rem;
    width: 100%;
    display: flex;
    overflow: hidden;
}
.classify-nav {
    width: 0.9rem;
    background: #f2f2f2;
    position: relative;
}
.classify-nav::after {
    content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    border-right: 1px solid #ccc;
    transform: scale(0.5, 1)
}
.classify-nav-list {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}
.classify-nav-item {
    height: 0.44rem;
    line-height: 0.44rem;
    width: 100%;
    background: #f2f2f2;
    position: relative;
    box-sizing: border-box;
}

.classify-nav-item::after {
    content: "";
    position: absolute;
    bottom: 0;
    width: 100%;
    left: 0;
    border-bottom: 1px solid #ccc; 
    transform: scale(1, 0.5)

}
.classify-nav-item-actived {
    background: #fff;
    width: 100%;
}
.classify-nav-item-actived::before {
     content: "";
    position: absolute;
    top: 0;
    right: 0;
    bottom: 0;
    border-right: 1px solid #fff;
    transform: scale(0.5, 1)
}
.classify-goods {
    flex: 1;
    padding: 0 0.14rem;
}
.classify-goods-list {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
}
.classify-goods-item {
    height: 1rem;
    display: flex;
    align-items: center;
    position: relative;
}
.classify-goods-item::after {
    content: "";
    position: absolute;
    left: 0;
    width: 100%;
    bottom: 0;
    border-top: 1px solid #f1f2f6;
    transform: scale(1, 0.5);
}
.classify-goods-img {
    width: 0.8rem;
    height: 0.8rem;
    margin-right: 0.1rem;
}
.classify-goods-con {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    justify-content: space-between;
}
.classify-goods-name {
    text-align: left;
    font-size: 0.14rem;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
    height: 0.28rem;
}
.classify-goods-feture {
    padding: 0.03rem 0 0.06rem 0;
    font-size: 0.12rem;
    color: #999;
}
.classify-goods-price {
    font-size: 0.12rem;
    color: #dd3333;
}
.boldNum {
    font-size: 0.16rem;
    margin-right: -0.04rem;
}
</style>